﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Service.Infrastructure;
using Truextend.CoffeShop.Model;
using Truextend.CoffeShop.Bussiness.Interfaces;
using Truextend.CoffeShop.Bussiness;

namespace Truextend.CoffeShop.Service
{
    public class ConsumptionService : BaseService
    {
        public void AddConsumptionByInternalProducts(int productId, Consumption consumption)
        {
            ExecuteManager(uow => 
                                {
                                    IProductManager productManager = new ProductManager(uow);
                                    IDetailManager detailManager = new DetailManager(uow, productManager);
                                    IConsumptionManager consumptionManager = new ConsumptionManager(uow,detailManager);                                    

                                    consumptionManager.AddConsumptionByInternalProducts(productId,consumption);
                                });            

        }        

        public void AddConsumptionByOrder(int detailId, Consumption consumption)
        {
            ExecuteManager(uow => 
                            {
                                IProductManager productManager = new ProductManager(uow);
                                IDetailManager detailManager = new DetailManager(uow, productManager);
                                IConsumptionManager consumptionManager = new ConsumptionManager(uow, detailManager);

                                consumptionManager.AddConsumptionByOrder(detailId,consumption);

                            });            

        }

        public IList<Consumption> GetAllConsumptionsOfADetail(int detailId) {

            IList<Consumption> result = null;

            ExecuteManager(uow => 
                            {
                                IProductManager productManager = new ProductManager(uow);
                                IDetailManager detailManager = new DetailManager(uow, productManager);
                                IConsumptionManager consumptionManager = new ConsumptionManager(uow, detailManager);

                                result = consumptionManager.GetAllConsumptionsOfADetail(detailId);
                            });

            return result;
        }

        public Consumption GetConsumptionForDetailAndUserID(int detailId, int userId)
        {
            Consumption result = null;

            ExecuteManager(uow =>
                               {
                                   IProductManager productManager = new ProductManager(uow);
                                   IDetailManager detailManager = new DetailManager(uow, productManager);
                                   IConsumptionManager consumptionManager = new ConsumptionManager(uow, detailManager);

                                   result = consumptionManager.GetConsumptionForDetailAndUserID(detailId, userId);   

                               });

            return result;
        }

        public void DeleteConsumption(Consumption consumption)
        {
            ExecuteManager(uow =>
                               {
                                   IProductManager productManager = new ProductManager(uow);
                                   IDetailManager detailManager = new DetailManager(uow, productManager);
                                   IConsumptionManager consumptionManager = new ConsumptionManager(uow, detailManager);

                                   consumptionManager.DeleteConsumption(consumption);
                               });
        }
    }
}
